/* Includes ------------------------------------------------------------------*/
#include "bluetooth.h"
#include "gpio.h"
#include "oled.h"
#include "beep.h"

/*----------------------------------------------------------------------------*/
/* Configure bluetooth                                                        */
/*----------------------------------------------------------------------------*/

uint8_t state_buffer = 0;

void BLUETOOTH_Init(void) {
  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(bluetooth_GPIO_Port, bluetooth_Pin, GPIO_PIN_SET);

  /*Configure GPIO pins : PBPin PBPin */
  GPIO_InitStruct.Pin = bluetooth_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  HAL_GPIO_Init(bmp_GPIO_Port, &GPIO_InitStruct);
}

void BLUETOOTH_State(void) {
  uint8_t state = HAL_GPIO_ReadPin(bluetooth_GPIO_Port, bluetooth_Pin);
  if (state != state_buffer) {
    if (state) {
      OLED_ShowChar(20, 0, 'B');
    } else {
      OLED_ShowChar(20, 0, ' ');
    }

    BEEP_Connect(state);
  }

  state_buffer = state;
}
